{{.content}}
<!-- 分页 -->
<nav class="mt-4 d-flex fixed-bottom justify-content-center" style="font-family: 'Noto Serif SC', serif, 'Arial', sans-serif; font-size: 16px;">
    {{.page}}
</nav>
<script>
document.addEventListener('DOMContentLoaded', function() {
  // 1. 安全获取当前页码（兼容第一页）
  const getCurrentPage = () => {
    // 尝试获取禁用项的页码
    const disabledItems = document.querySelectorAll('.page-item.disabled');
    for (const item of disabledItems) {
      if (item.querySelector('.page-link')) {
        const pageText = item.querySelector('.page-link').textContent;
        const pageNum = parseInt(pageText);
        if (!isNaN(pageNum)) return pageNum;
      }
    }
    
    // 备选方案：从URL参数获取
    const urlParams = new URLSearchParams(window.location.search);
    return parseInt(urlParams.get('page')) || 1;
  };
  
  // 2. 准确获取最大页码
  const getMaxPage = () => {
    let maxPage = 0;
    document.querySelectorAll('.page-item .page-link').forEach(link => {
      const pageNum = parseInt(link.textContent);
      if (!isNaN(pageNum) && pageNum > maxPage) maxPage = pageNum;
    });
    return maxPage;
  };
  
  // 3. 从当前URL提取保留PPT ID
  const getPresentationId = () => {
    // 从分页链接提取ID
    const firstLink = document.querySelector('.pagination a.page-link');
    if (firstLink) {
      const match = firstLink.href.match(/\/show\/(\d+)/);
      if (match) return match[1];
    }
    
    // 从当前URL提取ID
    const currentMatch = window.location.pathname.match(/\/v1\/ppt\/show\/(\d+)/);
    return currentMatch ? currentMatch[1] : '1'; // 默认值
  };

  // 翻页函数
  function goToPage(page) {
    const pptId = getPresentationId();
    window.location.href = `/show/${pptId}?page=${page}`;
  }

  // 鼠标左键和空格/方向键下一页
  document.addEventListener('click', (e) => {
    // 排除分页控件点击和特殊元素
    if (e.target.closest('.pagination')) return;
    {{range $v := .dianjigongnen}}
      if (e.target.closest('{{$v.classORid}}')) return;
    {{end}}
    
    if (['A', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'].includes(e.target.tagName)) return;
    
    const current = getCurrentPage();
    const maxPage = getMaxPage();
    if (current < maxPage) goToPage(current + 1);
  });

  // 右键点击事件（上一页）
  document.addEventListener('contextmenu', (e) => {
    // 排除特殊元素
    if (['A', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'].includes(e.target.tagName)) return;
    
    e.preventDefault(); // 阻止右键菜单
    const current = getCurrentPage();
    if (current > 1) goToPage(current - 1);
  });

  // 键盘事件
  document.addEventListener('keydown', (e) => {
    // 排除表单元素
    if (['INPUT', 'TEXTAREA', 'SELECT'].includes(document.activeElement.tagName)) return;
    
    const current = getCurrentPage();
    const maxPage = getMaxPage();
    
    switch (e.key) {
      case ' ':
      case 'ArrowDown':
      case 'ArrowRight':
        if (current < maxPage) {
          goToPage(current + 1);
          e.preventDefault();
        }
        break;
      case 'ArrowUp':
      case 'ArrowLeft':
        if (current > 1) {
          goToPage(current - 1);
          e.preventDefault();
        }
        break;
    }
  });
});
</script>
</body>

</html>